package com.qianfan.qfcall.network.repository

import com.qianfan.qfcall.network.response.BaseResponse
import com.sum.network.error.ApiException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

open class BaseRepository {

    suspend fun <T> requestResponse(requestCall:suspend ()-> BaseResponse<T>):T? {
        val response = withContext(Dispatchers.IO) {
            requestCall()
        }
        if (response.isFailed) {
            throw ApiException(response.code, response.msg)
        }
        return response.data
    }
}